package com.lantosec.hmrp.modules.archives.controller;


import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.archives.service.IUserContractService;
import com.lantosec.hmrp.modules.archives.vo.UserContractVO;

import java.util.Arrays;
import java.util.List;

import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 * 合同信息表 控制器
 *
 * @author AutoCode
 * @since 2020-06-09
 */
@Api(value = "合同信息表控制器", tags = "合同信息表控制器")
@RestController
@RequestMapping("/archives/user/contract")
@Log4j2
public class UserContractController extends BaseController {
    @Autowired
    private IUserContractService service;


    @GetMapping("getUserContract/{userId}")
    @ApiOperation(value = "查询用户合同信息")
    public Result<List<UserContractVO>> getUserContract(@ApiParam(value = "userId", required = true) @PathVariable(name = "userId") String userId) {
        List<UserContractVO> userContractVOList = service.getUserContract(userId);
        return Result.ok(userContractVOList);
    }

    @GetMapping("getUserContractVerify/{userId}")
    @ApiOperation(value = "查询用户合同信息审核列表")
    public Result<List<UserContractVO>> getUserOfficeVerify(@ApiParam(value = "userId", required = true) @PathVariable(name = "userId") String userId) {
        List<UserContractVO> userContractVOList = service.getUserContractVerify(userId);
        return Result.ok(userContractVOList);
    }

    @PutMapping("verifyUserContract")
    @ApiOperation(value = "审核")
    public Result<Void> verifyUserContract(@ApiParam(value = "用户任职信息表VO对象", required = true) @RequestBody UserContractVO vo) {
        service.verifyUserContract(vo);
        return Result.ok();
    }

    @GetMapping("getUserContractHistory/{userId}")
    @ApiOperation(value = "查询用户合同信息历史列表")
    public Result<List<UserContractVO>> getUserContractHistory(@ApiParam(value = "userId", required = true) @PathVariable(name = "userId") String userId) {
        List<UserContractVO> userContractVOList = service.getUserContractHistory(userId);
        return Result.ok(userContractVOList);
    }


    @PostMapping("create")
    @ControllerLog(name = "新增用户合同信息", type = LogType.add)
    @ApiOperation(value = "新增用户合同信息")
    public Result<String> create(@ApiParam(value = "合同信息表VO对象", required = true) @RequestBody @Validated UserContractVO vo) {
        service.saveUserContract(vo);
        return Result.ok();
    }

    @PutMapping("update")
    @ControllerLog(name = "修改用户合同信息", type = LogType.update)
    @ApiOperation(value = "修改用户合同信息")
    public Result<Void> update(@ApiParam(value = "合同信息表VO对象", required = true) @RequestBody UserContractVO vo) {
        service.updateUserContract(vo);
        return Result.ok();
    }

    @DeleteMapping(value = "delete/{ids}")
    @ControllerLog(name = "逻辑删除用户合同信息", type = LogType.delete)
    @ApiOperation("逻辑删除")
    public Result<Void> delete(@ApiParam(value = "ID列表,用逗号分隔", required = true) @PathVariable(name = "ids") String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            service.removeByIds(Arrays.asList(ids.split(",")));
        }
        return Result.ok();
    }
}
